

/**
 * @file CSDetectorUC.hpp
 */

#ifndef GPSTK_CSDetectorUC_HPP
#define GPSTK_CSDetectorUC_HPP


#include <deque>
#include "ProcessingClass.hpp"
#include "CSDetectorLC.hpp"
#include "CSDetectorWL.hpp"
#include "SatID.hpp"

namespace gpstk
{

      /** @addtogroup GPSsolutions */
      //@{

   class CSDetectorUC : public ProcessingClass
   {
   public:

         /// Default constructor, setting default parameters.
      CSDetectorUC() 
          : 
            firstTime(true),
            deltaTMax(91.0), useLLI(true),
            threshold(0.86),
            sampleInterval(30.0),
            pLCDetector(NULL), pWLDetector(NULL)
      {};


         /** Returns a satTypeValueMap object, adding the new data generated
          *  when calling this object.
          *
          * @param epoch     Time of observations.
          * @param gData     Data object holding the data.
          * @param epochflag Epoch flag.
          */
      virtual satTypeValueMap& Process( const CommonTime& epoch,
                                        satTypeValueMap& gData )
         noexcept(false);

      virtual void setLCDetector(CSDetectorLC& detector)
      {
          pLCDetector = &detector;
      };

      virtual void setWLDetector(CSDetectorWL& detector)
      {
          pWLDetector = &detector;
      };

      virtual double getDeltaTMax() const
      { return deltaTMax; };

      virtual CSDetectorUC& setDeltaTMax(const double& maxDelta);

      virtual double getSampleInterval() const
      { 
          return sampleInterval; 
      };

      virtual CSDetectorUC& setSampleInterval(const double interval)
      {
          sampleInterval = interval;
          return (*this);
      };

         /// Method to know if the LLI check is enabled or disabled.
      virtual bool getUseLLI() const
      { return useLLI; };


         /** Method to set whether the LLI indexes will be used as an aid
          *  or not.
          *
          * @param use   Boolean value enabling/disabling LLI check
          */
      virtual CSDetectorUC& setUseLLI(const bool& use)
      { useLLI = use; return (*this); };


      virtual CSDetectorUC& setType(TypeID type, SatelliteSystem::Systems sys)
      {   
          ucType = type;
          satSys = sys; 
          
          if(satSys == SatelliteSystem::GPS)
          {
              if(ucType == TypeID::L1)
              {
                  prefitType = TypeID::prefitL1;
                  diffIonoType = TypeID::diffIonoL1;
                  diffPrefitType = TypeID::diffPrefitL1;
                  diffPostType = TypeID::diffPostfitL1;
                  waveLength = L1_WAVELENGTH_GPS;
              }
          }
          else
          {
              cerr << "CSDetectorUC:: dont's support this system " << endl;
              exit(-1);
          }

          return (*this); 
      };

         /** Returns a gnnsRinex object, adding the new data generated when
          *  calling this object.
          *
          * @param gData    Data object holding the data.
          */
      virtual void Process(gnssRinex& gData)
         noexcept(false);

      virtual void getEpochDiffData(satTypeValueMap& sData);

      virtual void setCSDataStream(std::ofstream& stream)
      {
          pCSDataStream = &stream;
      };


         /// Returns a string identifying this object.
      virtual std::string getClassName(void) const;


         /// Destructor
      virtual ~CSDetectorUC() {};


   private:

      bool firstTime;

      TypeID ucType;
      SatelliteSystem::Systems satSys;

      TypeID prefitType;
      TypeID diffPrefitType;
      TypeID diffPostType;
      TypeID diffIonoType;
      double waveLength;

      /// Maximum interval of time allowed between two successive epochs,
      /// in seconds.
      double deltaTMax;

      double threshold;

         /// This field tells whether to use or ignore the LLI indexes as
         /// an aid.
      bool useLLI;

      double sampleInterval;

      satTypeValueMap stvDataPrev;

      CSDetectorLC* pLCDetector;
      CSDetectorWL* pWLDetector;

      std::ofstream* pCSDataStream;


  }; // End of class 'CSDetectorUC'

      //@}

}  // End of namespace gpstk

#endif   // GPSTK_CSDetectorUC_HPP
